package com.sinodata.bsm.center.engine.notify.impl;

import java.text.SimpleDateFormat;

import org.apache.log4j.Logger;

import com.sino.uam.entity.UserInfo;
import com.sinodata.bsm.center.engine.notify.NotifyMode;
import com.sinodata.bsm.common.constants.EventConstants;
import com.sinodata.bsm.common.vo.Event;
import com.sinodata.bsm.common.vo.Notify;

/**
 * 
 * <p>
 * Description: 短信通知实现类
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-8-9 PM 4:10:29      liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class SmsNotifyModeImpl implements NotifyMode {

    private static final Logger logger = Logger.getLogger(SmsNotifyModeImpl.class);

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createNotifyMessage(com.sinodata.bsm.common.vo.Event)
     */
    @Override
    public String createNotifyMessage(Event eventValue) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = formatter.format(eventValue.getOccurTime());
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.append("【" + EventConstants.getLevelDesc(eventValue.getLevel()) + "】");
        String notifyMessage = eventValue.getMsg();
        //发送通知消息时计算实时的通知信息 //暂且不启用
        //        if (eventValue.getMsgExpr() != null && !eventValue.getMsgExpr().equals("") && eventValue.getCatalog() != EventConstants.CATALOG_USABLEEVENT) {
        //            try {
        //                Object msg = Expressions.eval(eventValue.getMsgExpr());
        //                if (msg != null && msg instanceof String) {
        //                    notifyMessage = (String) msg;
        //                }
        //            } catch (Exception e) {
        //                logger.error("failed to calc real-time notify message,used original notify message", e);
        //            }
        //        }
        strBuilder.append(notifyMessage);
        strBuilder.append(" ");
        strBuilder.append(date);
        return strBuilder.toString();
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createResumeMessage(com.sinodata.bsm.common.vo.Event)
     */
    @Override
    public String createResumeMessage(Event eventValue) {
        StringBuilder sb = new StringBuilder();
        sb.append("【故障已恢复】【系统自动清除事件】");
        sb.append(eventValue.getMsg());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = formatter.format(eventValue.getOccurTime());
        sb.append(" ");
        sb.append(date);
        return sb.toString();
    }

    /*
     * (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#getNotifyDestination(com.sino.uam.entity.UserInfo)
     */
    @Override
    public String getNotifyDestination(UserInfo userInfo) {
        return userInfo.getMobileTel();
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.engine.notify.NotifyMode#createMsg()
     */
    @Override
    public String createMsg(Notify notify) {
        return null;
    }

}